<?php
namespace App\Http\Controllers\Api;

use App\Model\AdminIp;
use Illuminate\Http\Request;
use App\Model\OperationLogs;

class AdminIpController extends BaseController
{
    protected $model = null;

    public function __construct(Request $request)
    {
        parent::__construct($request);
        $this->model = new AdminIp();
    }

    //后台ip白名单列表
    public function list(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->list($request));
    }

    //后台ip白名单新增
    public function add(Request $request){
        $res = $this->model->add($request->all(), $this->user);
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACCOUNT, '后台ip白名单新增');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //后台ip白名单删除
    public function del(Request $request){
        $res = $this->model->del($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACCOUNT, '后台ip白名单删除');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //后台ip白名单显示状态
    public function status(Request $request){
        $res = $this->model->status($request->all());
        if($res['code'] == self::SUCCESS) {
            OperationLogs::createData($request, OperationLogs::ACCOUNT, '后台ip白名单显示状态');
        }
        return $this->toJson($res['code'], $res['data'], $res['msg']);
    }

    //管理员ip操作记录
    public function ipOptList(Request $request){
        return $this->toJson(self::SUCCESS, $this->model->optIpList($request));
    }


}
